/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "CameraDesc.h"

namespace liba
{
namespace lib3d
{


CameraDesc::CameraDesc()
:	near_plane( 0 ),
	far_plane( 0 ),
	viewport( -1, 1, 1, -1 ),
	fog_color( 1, 1, 1 ),
	fog_range( 0 )
{}

bool CameraDesc::is_sphere_visible( const math::Sphere & sphere )
{
	math::Intersect::Type type = frustrum.intersects( sphere );
	return type != math::Intersect::DISJOINT;
}

bool CameraDesc::is_box_visible( const math::Box & box )
{
	math::Intersect::Type type = frustrum.intersects( box );
	return type != math::Intersect::DISJOINT;
}

Ray CameraDesc::get_ray(double px, double py)const
{
	Vector dir( float(px), float(py), 1 );
	Matrix view_mat = Matrix::invert( world );
	Matrix inv_mat = Matrix::invert( view_mat * projection );
	dir = dir * inv_mat;
	return Ray( world.shift(), Vector::normalize(dir) );
}

} // namespace lib3d
} // namespace liba

